<?php

/**
 * This is the model class for table "public.site".
 */
require_once(dirname(__FILE__) . '/base/SiteBase.php');
class Site extends SiteBase
{
    const STATUS_DEACTIVE = 0, STATUS_ACTIVE = 1;

    public $urls;

    public function behaviors()
    {
        return array(
            'timestamp' => array(
                'class' => 'TimestampBehavior',
            ),
        );
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        return CMap::mergeArray(parent::rules(), array(
            array('urls, fav_icon', 'safe'),
            array('name', 'unique'),
        ));
    }

    public function getStatusOptions()
    {
        return array(
            self::STATUS_DEACTIVE => 'Deactive',
            self::STATUS_ACTIVE => 'Active',
        );
    }

    public function getStatusText()
    {
        $options = $this->getStatusOptions();
        return isset($options[$this->status]) ? $options[$this->status] : Yii::t('app', 'Unknown {att}', array('{att}' => $this->status));
    }

    /**
     * List sites by key-value pair
     *
     */
    public static function siteList()
    {
        $sites = Site::model()->findAll();
        $siteList = array();
        if (is_array($sites)) {
            foreach ($sites as $site) {
                $siteList[$site->id] = $site->name;
            }
        }
        return $siteList;
    }

    public static function getSiteNameById($siteId)
    {
        $siteList = self::siteList();
        return isset($siteList[$siteId]) ? $siteList[$siteId] : Yii::t('app', 'Unknown {att}', array('{att}' => $siteId));
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        $criteria = new CDbCriteria;

        $criteria->compare('name', $this->name, true);

        return new CActiveDataProvider(get_class($this), array(
            'criteria' => $criteria,
            'sort' => array(
                'defaultOrder' => 'name'
            ),
            'pagination' => array(
                'pageSize' => Settings::BO_PAGE_SIZE,
            ),
        ));
    }

    public function getLocaleIDOptions()
    {
        //$localeIDs = CLocale::getLocaleIDs();
        //return array_combine($localeIDs, $localeIDs);
        return array(
            'en_us' => 'English - United States',
            'en_ca' => 'English - Canada',
            'fr_ca' => 'French - Canada',
            'es_es' => 'Spanish - Spain',
        );
    }
}